package com.hdcircles.autoform.ui.main.activity;

import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hdcircles.autoform.R;
import com.hdcircles.autoform.base.BaseActivity;
import com.hdcircles.autoform.component.ImageLoader;
import com.hdcircles.autoform.model.bean.WelcomeBean;
import com.hdcircles.autoform.presenter.WelcomePresenter;
import com.hdcircles.autoform.presenter.contract.WelcomeContract;
import com.hdcircles.autoform.util.SharedPreferenceUtil;

import butterknife.BindView;

/**
 * Created by hdcircles on 2016/9/23.
 */


public class WelcomeActivity extends BaseActivity<WelcomePresenter> implements WelcomeContract.View {


    @BindView(R.id.iv_welcome_bg)
    ImageView ivWelcomeBg;
    @BindView(R.id.tv_welcome_author)
    TextView tvWelcomeAuthor;

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initEventAndData() {
        mPresenter.getWelcomeData();
    }

    @Override
    public void showContent(WelcomeBean welcomeBean) {
        ImageLoader.load(this,welcomeBean.getImg(),ivWelcomeBg);
        ivWelcomeBg.animate().scaleX(1.12f).scaleY(1.12f).setDuration(2000).setStartDelay(100).start();
        tvWelcomeAuthor.setText(welcomeBean.getText());
    }

    @Override
    public void jump2Main() {
        Intent intent=new Intent();
        if (SharedPreferenceUtil.getUserEmail().length()==0){
            intent.setClass(this,LoginActivity.class);
        }else {
            intent.setClass(this,MainActivity.class);
        }
        startActivity(intent);
        finish();
        overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Glide.clear(ivWelcomeBg);
    }

    @Override
    public void showError(String msg) {

    }


}
